package com.ld.control.business.customer.controller;


import com.ld.control.business.customer.service.CustomerService;
import com.ld.control.business.customer.vo.req.CustomerReqVo;
import com.ld.control.business.customer.vo.reqsp.CustomerRespVo;
import com.ld.control.business.equipment.vo.resp.EquipmentRespVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2024-05-06
 */
@Slf4j
@Tag(name = "客户相关接口")
@RestController
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @GetMapping("/api/centralControl/customer/getPageList")
    @Operation(summary = "客户列表")
    public ResultResponse<GeneratePageListVo<CustomerRespVo>> getPageList(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String companyName,
            @RequestParam(required = false, defaultValue = "1") Integer current,
            @RequestParam(required = false, defaultValue = "10") Integer size
    ){
        GeneratePageListVo<CustomerRespVo> customerServicePageList = customerService.getPageList(name, companyName, current, size);
        return ResultResponse.success(customerServicePageList);
    }

    @GetMapping("/api/centralControl/customer/getById")
    @Operation(summary = "客户详情")
    public ResultResponse<CustomerRespVo> getById(
            @RequestParam Long id
    ) {
        CustomerRespVo customerRespVo = customerService.getById(id);
        return ResultResponse.success(customerRespVo);
    }

    @PostMapping("/api/centralControl/customer/add")
    @Operation(summary = "新增客户信息")
    public ResultResponse<ResultResponseEnum> add(
            @RequestBody CustomerReqVo customerReqVo
    ) {
        customerService.add(customerReqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/customer/update")
    @Operation(summary = "修改客户信息")
    public ResultResponse<ResultResponseEnum> update(
            @RequestBody CustomerReqVo customerReqVo
    ) {
        customerService.update(customerReqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/customer/delete")
    @Operation(summary = "删除客户信息")
    public ResultResponse<ResultResponseEnum> delete(
            @RequestParam Long id
    ) {
        customerService.deleteById(id);
        return ResultResponse.success();
    }
}

